<?php

class Application_Form_ChangeMail extends Zend_Form
{

    public function init()
    {
        $this->setMethod('post')
        	->setAttrib('id', 'changeMailForm');
        
        $this->clearDecorators();
        $this->addElementPrefixPath('ViewOnceUrlGen_Validate', 'ViewOnceUrlGen/Validate/', 'validate');
        
        $decorators = array(
        		array('ViewHelper'),
        		array('Errors'),
        		array('Label', array('requiredSuffix' => ' *', 'class' => 'leftalign')),
        		array('HtmlTag', array('tag' => 'li')),
        );
        
        $currentEmail = $this->addElement('text', 'currentEmail',
        		array('label' => 'Current Email Address'));
        $currentEmail = $this->getElement('currentEmail')
        	->addValidator('EmailAddress')
        	->addValidator('EmailIdenticalToCurrent')
        	->setRequired(true)
        	->addFilter('StringTrim');
        $currentEmail->getValidator('EmailAddress')->setMessage('Invalid email address');
        $currentEmail->setDecorators($decorators);
        
        $newEmail = $this->addElement('text', 'newEmail',
        		array('label' => 'New Email Address'));
        $newEmail = $this->getElement('newEmail')
        		->addValidator('EmailAddress')
        		->addValidator('EmailNotIdenticalToCurrent')
        		->setRequired(true)
        		->addFilter('StringTrim');
        $newEmail->getValidator('EmailAddress')->setMessage('Invalid email address');
        $newEmail->getValidator('EmailNotIdenticalToCurrent')->setMessage('New email address is the same as the current one');
        $newEmail->setDecorators($decorators);
        
        $confirmEmail = $this->addElement('text', 'confirmEmail',
        		array('label' => 'Confirm Email Address'));
        $confirmEmail = $this->getElement('confirmEmail')
        	->addValidator('Identical', false, array('token' => 'newEmail'))
        	->setRequired(true)
        	->addFilter('StringTrim');
        $confirmEmail->getValidator('Identical')
        	->setMessage('Email Confirmation does not match');
        $confirmEmail->setDecorators($decorators);
        
        $submit = $this->addElement('submit', 'save',
        		array('label' => 'Save'));
        $submit = $this->getElement('save')
        ->setDecorators(array(
        		array('ViewHelper'),
        ));
        
        $cancel = $this->addElement('submit', 'cancel',
        		array('label' => 'Cancel'));
        $cancel = $this->getElement('cancel')
        	->setDecorators(array(
        		array('ViewHelper'),
        ));
        
        $this->addDisplayGroup(array('save', 'cancel'), 'submit_buttons',
        		array('disableLoadDefaultDecorators' => true));
        $submitButtons = $this->getDisplayGroup('submit_buttons');
        $submitButtons->addDecorators(array(
        		array('FormElements', 'Form'),
        		array('HtmlTag', array('tag' => 'li', 'class' => 'submit')),
        ));
        
        $this->setDecorators(array(
        		'FormElements',
        		array('HtmlTag', array('tag' => 'ul')),
        		array(array('DivTag' => 'HtmlTag'),
        				array('tag' => 'div', 'id' => 'changeMailDiv')),
        		'Form'
        ));
    }
}

